package com.hyy.provider.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaCheckLogin;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hyy.common.idempotent.annotation.RepeatSubmit;
import com.hyy.common.log.annotation.Log;
import com.hyy.common.web.core.BaseController;
import com.hyy.common.mybatis.core.page.PageQuery;
import com.hyy.common.core.domain.R;
import com.hyy.common.core.validate.AddGroup;
import com.hyy.common.core.validate.EditGroup;
import com.hyy.common.log.enums.BusinessType;
import com.hyy.common.excel.utils.ExcelUtil;
import com.hyy.api.domain.provider.vo.ProvCorporateVo;
import com.hyy.api.domain.provider.bo.ProvCorporateBo;
import com.hyy.provider.service.IProvCorporateService;
import com.hyy.common.mybatis.core.page.TableDataInfo;

/**
 * 供应商公司信息
 *
 * @author ruoyi
 * @date 2025-05-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/provider/corporate")
public class ProvCorporateController extends BaseController {

    private final IProvCorporateService provCorporateService;

    /**
     * 查询供应商公司信息列表
     */
    @SaCheckPermission("provider:corporate:list")
    @GetMapping("/list")
    public TableDataInfo<ProvCorporateVo> list(ProvCorporateBo bo, PageQuery pageQuery) {
        return provCorporateService.queryPageList(bo, pageQuery);
    }
    /**
     * 查询供应商公司信息列表
     */
    @SaCheckLogin
    @GetMapping("/listAll")
    public List<ProvCorporateVo> listAll() {
        return provCorporateService.queryList(new ProvCorporateBo());
    }

    /**
     * 导出供应商公司信息列表
     */
    @SaCheckPermission("provider:corporate:export")
    @Log(title = "供应商公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ProvCorporateBo bo, HttpServletResponse response) {
        List<ProvCorporateVo> list = provCorporateService.queryList(bo);
        ExcelUtil.exportExcel(list, "供应商公司信息", ProvCorporateVo.class, response);
    }

    /**
     * 获取供应商公司信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("provider:corporate:query")
    @GetMapping("/{id}")
    public R<ProvCorporateVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(provCorporateService.queryById(id));
    }

    /**
     * 新增供应商公司信息
     */
    @SaCheckPermission("provider:corporate:add")
    @Log(title = "供应商公司信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ProvCorporateBo bo) {
        return toAjax(provCorporateService.insertByBo(bo));
    }

    /**
     * 修改供应商公司信息
     */
    @SaCheckPermission("provider:corporate:edit")
    @Log(title = "供应商公司信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ProvCorporateBo bo) {
        return toAjax(provCorporateService.updateByBo(bo));
    }

    /**
     * 删除供应商公司信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("provider:corporate:remove")
    @Log(title = "供应商公司信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(provCorporateService.deleteWithValidByIds(List.of(ids), true));
    }
}
